import os

from django.conf import settings
from django.views import View

from User.models import User, Order, OrderYard, OrderVip, OrderGoods, OrderRent
from Venue import Constants
from sportsground.utils import Req
from sportsground.utils.Res import Res
from sportsground.utils.views import LoginRequiredVenue


class CapitalView(LoginRequiredVenue,View):
    """ 资金流水 """

    def get(self, request):
        """ 查询 """
        venue = request.user.venue

        lists = {}

        orderYards = OrderYard.objects.order_by("-createTime").all()
        yards = [orderYard.capitalInfo() for orderYard in orderYards ]
        lists['yards'] = yards

        orderVips = OrderVip.objects.order_by("-createTime").all()
        vips = [orderVip.capitalInfo() for orderVip in orderVips]
        lists['vips'] = vips

        orderGoodses = OrderGoods.objects.order_by("-createTime").all()
        goods = [orderGoods.capitalInfo() for orderGoods in orderGoodses]
        lists['goods'] = goods

        orderRents = OrderRent.objects.order_by("-createTime").all()
        rents = [orderRent.capitalInfo() for orderRent in orderRents]
        lists['rents'] = rents
        return Res.Json(Res.OK, result=lists)
